package com.sk.bilibili.other;

import lombok.SneakyThrows;

import java.lang.reflect.Field;

/**
 * @author 邵康
 * @date 2021/12/19 11:16
 */
public class RedisKeyGenerator {

    private String simpleName;
    private Field idFiled;
    private static final String ID_FIELD_NAME="id";

    @SneakyThrows
    public RedisKeyGenerator(Class<?> clazz) {
        simpleName=clazz.getSimpleName();
        idFiled=clazz.getDeclaredField(ID_FIELD_NAME);
        idFiled.setAccessible(true);
    }

    @SneakyThrows
    public String generateKey(Object target){
        return simpleName+"-"+idFiled.get(target);
    }

}
